package com.kuzan.autocloud.common.model.system;

import com.kuzan.autocloud.common.model.Base;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * <p>Description: </p>
 *
 * @author kuzank 2019/12/1
 */
@Data
@NoArgsConstructor
@Entity
@Table(name = "sys_permission")
public class ACPermission extends Base {

    @Column(length = 32)
    private String resource;
    /**
     * personid & organizationid & rolegroupid
     */
    @Column(length = 32)
    private String identity;
    @Column(length = 32)
    private String type;

    /**
     * 菜单权限类型
     */
    public enum ACPermissionType {
        pid("permissionType"),

        Person("pt_person"),
        Orgunation("pt_orgunation"),
        Role("pt_role");

        private String name;

        ACPermissionType(String name) {
            this.name = name;
        }

        public String value() {
            return name;
        }

        public String getName() {
            return name;
        }
    }

    public static ACPermission of(String id, String resource, String identity, ACPermissionType type) {
        ACPermission obj = new ACPermission();
        obj.setId(id);
        obj.setResource(resource);
        obj.setIdentity(identity);
        obj.setType(type.getName());
        return obj;
    }
}
